#include <iostream>
#include "html_writer.hpp"


void HTMLWriter::setOutput(string file_name) {
	file.open(file_name.c_str());
}
void HTMLWriter::setStylesheet(string stylesheet_name) {
	css = stylesheet_name;
}

void HTMLWriter::startDoc() {
	file << "<html>\n";
	file << "<head>\n";
	file << "\t<link href=\"" << css << "\" rel=\"stylesheet\" type=\"text/css\">\n";
	file << "</head>\n";
	file << "</body>\n";
	
	writeKW("void ");
	file << "<span class=\"Main Key\">main</span>";
	writeSEP("() ");
	
	file << endl;

}

void HTMLWriter::endDoc() {
	file << endl << "</body>\n";
	file << "</html>\n";
	file.close();
}

void HTMLWriter::writeKW(string kw) {
	writeSpan("Key", kw);
}
void HTMLWriter::writeID(string id) {
	writeSpan("Id", id);
}
void HTMLWriter::writeLIT(string lit) {
	writeSpan("Lit", lit);
}
void HTMLWriter::writeSEP(string sep) {
	writeSpan("Sep", sep);
}
void HTMLWriter::writeOP(string op) {
	writeSpan("Op", op);
}

void HTMLWriter::declarationStart(string type) {
	writeKW(type);
}
void HTMLWriter::declarationAdd(string identifier) {
	file << " ";
	writeID(identifier);
}

void HTMLWriter::sentenceEnd() {
	writeSEP(";");
	file << "<br>" << endl;
}


void HTMLWriter::openCB() {
	file << "<br>";
	writeSEP("{");
	file << endl;
	file << "<div class='CodeBlock'>" << endl;
}

void HTMLWriter::closeCB() {
	file << "</div>" << endl;
	writeSEP("}");
	file << "<br>";
	file << endl;
}


void HTMLWriter::writeSpan(string cl, string content) {
	file << "<span class='" << cl << "'>" << content << "</span>";
}
